import { UserConfigExport, loadEnv, ConfigEnv } from "vite";
import uni from "@dcloudio/vite-plugin-uni";
import { ExpandImportMetaEnv } from './src/utils/type'

export default (param: ConfigEnv): UserConfigExport => {
  const { mode } = param
  const env = loadEnv(mode, process.cwd()) as unknown as ExpandImportMetaEnv
  
  return {
    plugins: [
      uni()
    ],
    server: {
      port: 4022,
      proxy: {
        [env.VITE_REQUEST_BASE_URL]: {
          target: env.VITE_REQUEST_URL,
          changeOrigin: true,
          ws: true,
          rewrite: path => path.replace(
            env.VITE_REQUEST_BASE_URL, env.VITE_REQUEST_BASE_URL)
        }
      }
    },
    css: {
      preprocessorOptions: {
        scss: {
          additionalData: [
            'variable',
            'mixin' 
          ].map(item => `@use "@/styles/${item}.scss" as *;`).join('\n')
        }
      }
    }
  }
}